﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com;
using Com.GUI;
using Com.BU;
using Com.DA;
using ColdStorage.DOL;


namespace ColdStorage.GUI
{
    /// <summary>
    /// Interaction logic for ucConstructionCold.xaml
    /// </summary>
    public partial class ucConstructionCold : UserControl
    {
        public ucConstructionCold()
        {
            InitializeComponent();
            loadInfo();
           
        }

        public void loadInfo()
        {
            //Load loại Roof
            cbxRoofType.Items.Clear();
            LibraryManagerInCom.loadroofType();
            cbxRoofType.ItemsSource = LibraryManagerInCom.RoofList;
            cbxRoofType.DisplayMemberPath = "ceiling_type";
            cbxRoofType.SelectedIndex = -1;

            // Load loai tuong
            
            cbxWallType.Items.Clear();
            LibraryManagerInCom.loadWallType();
            cbxWallType.ItemsSource = LibraryManagerInCom.wallTypeList;
            cbxWallType.DisplayMemberPath = "wall_type";
            cbxWallType.SelectedIndex = -1;

            //Load vật liệu tường
            cbxWallMaterials.Items.Clear();
            LibraryManagerInCom.loadCSWallMaterialList();
            cbxWallMaterials.ItemsSource = LibraryManagerInCom.CSWallMaterialList;
            cbxWallMaterials.DisplayMemberPath = "wall_type";
            cbxWallMaterials.SelectedIndex = -1;

            // Load Hướng
            cbxDirection.Items.Clear();
            LibraryManagerInCom.loadDirection();
            cbxDirection.ItemsSource = LibraryManagerInCom.wallDirectionList;
            cbxDirection.DisplayMemberPath = "direction";
            cbxDirection.SelectedIndex = -1;

            //Load dữ liệu cho hệ số truyền nhiệt sàn
            txtFloorHeatTransferCoefficient.Text = "0.21";
            //Load hệ số truyền nhiệt cho Roof
            txtRoofTempExcess.Text = "0.2";

        }


       

        private void radYes_Checked(object sender, RoutedEventArgs e)
        {
            cbxDirection.IsEnabled = true;
            txtWallTempExcess.IsEnabled = true;
            lblWallTempExcess.IsEnabled = true;
            lblDirection.IsEnabled = true;
        }

        private void radNo_Checked(object sender, RoutedEventArgs e)
        {
            cbxDirection.IsEnabled = false;
            cbxDirection.Text = "";
            txtWallTempExcess.IsEnabled = false;
            txtWallTempExcess.Text = "";
            lblWallTempExcess.IsEnabled = false;
            lblDirection.IsEnabled = false;
        }

        private void cbxWallType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                txtWallHeatTransferCoefficient.Text = ((tb_wall_type)cbxWallType.SelectedItem).heat_transfer_coefficient.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void cbxDirection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                LibraryManagerInCom.loadCSWallMaterialList();
                LibraryManagerInCom.loadColdStorageWallList();
                tb_wall_direction wallDirection = (tb_wall_direction)cbxDirection.SelectedItem;
                tb_wall_material wallMaterial = (tb_wall_material)cbxWallMaterials.SelectedItem;
                tb_temperature_excess te = LibraryManagerInCom.ColdStorageWallList.SingleOrDefault
                    (s => s.wall_material_id == wallMaterial.id && s.direction_id == wallDirection.id);
                txtWallTempExcess.Text = te.termperature_excess.ToString();

                
            }
            catch (Exception ex)
            {

                MessageBox.Show("Chưa có dữ liệu cho Wall Material này");
            }
        }

        private void cbxWallMaterials_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                LibraryManagerInCom.loadCSWallMaterialList();
                LibraryManagerInCom.loadColdStorageWallList();
                tb_wall_direction wallDirection = (tb_wall_direction)cbxDirection.SelectedItem;
                tb_wall_material wallMaterial = (tb_wall_material)cbxWallMaterials.SelectedItem;
                tb_temperature_excess te = LibraryManagerInCom.ColdStorageWallList.SingleOrDefault
                    (s => s.wall_material_id == wallMaterial.id && s.direction_id == wallDirection.id);
                txtWallTempExcess.Text = te.termperature_excess.ToString();


            }
            catch (Exception ex)
            {

                MessageBox.Show("Chưa có dữ liệu cho Direction");
            }
        }

        private void ucConstruction_Loaded(object sender, RoutedEventArgs e)
        {
           
        }

        private void cbxRoofType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            txtRoofHeatTransferCoefficient.Text = ((tb_ceiling_type)cbxRoofType.SelectedItem).temperature_excess.ToString();
        }



        

        

        

    }
}
